<template>
  <div>
    <el-dialog class="select-prod" title="选择借用出库单" :visible.sync="borrowOrderVis" @close="close" width="900px" append-to-body :close-on-click-modal='false'>

        <el-row>
          <el-col :span="24">
            <el-table ref="prodInfos" :data="tableData" border style="width: 100%" @selection-change="selectProd">
              <el-table-column type="selection" width="40"></el-table-column>
              <el-table-column prop="dorderNum" label="出库单号"></el-table-column>
              <el-table-column prop="dtypeName" label="出库类型"></el-table-column>
              <el-table-column prop="outPerson" label="制单人"></el-table-column>
              <el-table-column prop="returnDate" label="归还日期"></el-table-column>
              <el-table-column prop="outDate" label="出库日期"></el-table-column>
              <el-table-column prop="outRemark" label="备注"></el-table-column>
            </el-table>
          </el-col>
        </el-row>

      <el-row>
        <el-col :span="24">
          <el-pagination
            class="pull-left"
            background
            :page-sizes="[10]"
            layout="total, prev, pager, next"
            :total="30">
          </el-pagination>
        </el-col>
      </el-row>

        <div slot="footer" class="dialog-footer">
          <el-button size="small" @click="close">取 消</el-button>
          <el-button size="small" type="primary" :loading="submitLoading" @click="selectprodSuccess()">确 定</el-button>
        </div>
    </el-dialog>
  </div>
</template>

<script>
import { GetProduct, SelectByProdInfo } from '@/api/prod';
export default {
  name: 'selectprod',
  props: ['returnOrderDialog'],
  data() {
    return {
      borrowOrderVis: false,
      submitLoading: false,
      formLabelWidth: '90px',
      categoryvalue: '',
      prod_code: '',
      prod_name: '',
      selectBorrowOrder: [],
      tableData: []
    }
  },
  mounted() {
    this.$store.commit('ware/SET_SELECTPROD', []);
    this.getProducts();
  },
  methods: {
    close() {
      this.borrowOrderVis = false;
      this.$emit("update:returnOrderDialog", false);
      this.$store.commit('ware/SET_SELECTPROD', []);
    },
    // 获取所有商品信息
    getProducts() {
      GetProduct().then( response => {
        let data = response.data;
        this.tableData = data;
      }).catch( error => {
        console.log(error)
      })
    },
    // 搜索商品
    searchProd() {
      let reqData = {
        prodCode: this.prod_code,
        prodName: this.prod_name,
      }
      SelectByProdInfo(reqData).then( res => {
        this.tableData = res.data.info
      })
    },
    // 选择借用出库单
    selectProd(val) {
      if (this.selectBorrowOrder.length >= 1) {
        this.$message({
          message: '只能选择一个借用出库单',
          type: 'success'
        })
        this.$refs.prodInfos.clearSelection()
        this.selectBorrowOrder = []
      } else {
        this.selectBorrowOrder = val;
      }
    },
    selectprodSuccess() {
     
      this.borrowOrderVis = false;
      this.$emit("update:returnOrderDialog", false);
      this.$refs.prodInfos.clearSelection()
    },
  },
  watch: {
    returnOrderDialog(newVal,oldVal) {  
      this.borrowOrderVis = newVal;
    }
  }
}
</script>

<style lang="scss" scoped>
@import '../../styles/config.scss';

  .label-wrap {
    &.category { @include labelwrap(left,50,40); }
    &.date {
      @include labelwrap(center,50,40); }
    &.keyword { @include labelwrap(right,110,40); }
  }
  .autospace {
    height: 30px;
  }
  
</style>